require "enum"
local tabletool = require "tabletool"
local msghelper = require "tablehelper"
local filelog = require "filelog"
local timer = require "timer"
local msgproxy = require "msgproxy"
local timetool = require "timetool"

local RoomSeatLogic = {}

function RoomSeatLogic.init(seatobj, index)
	seatobj.index = index
	seatobj.state = ESeatState.SEAT_STATE_NO_PLAYER
	seatobj.is_tuoguan = false
	return true
end

function RoomSeatLogic.clear(seatobj)
	seatobj.rid = 0
	seatobj.state = 0  --改坐位玩家状态
	seatobj.gatesvr_id=""
	seatobj.agent_address = -1
	seatobj.playerinfo = {}
end

function RoomSeatLogic.is_empty(seatobj)
	return (seatobj.state == ESeatState.SEAT_STATE_NO_PLAYER or seatobj.rid <= 0)
end


function RoomSeatLogic.clear_seat(seat)
	seat.rid = 0
	seat.state = ESeatState.SEAT_STATE_NO_PLAYER
	seat.gatesvr_id=""
	seat.agent_address = -1
	seat.playerinfo.rolename = ""
	seat.playerinfo.logo=""
	seat.playerinfo.sex = 0
	seat.is_tuoguan = false
	seat.is_robot = false
	seat.timeout_count = 0
	seat.win = 0
	seat.coin = 0
	seat.lottery = 0 --奖券
    seat.roomcard = 0 --玩家身上的房卡
    seat.gemstone = 0 --玩家的宝石
	seat.is_disconnected = false --玩家是否断线
	seat.cards = {}          --记录玩家手牌
	seat.cards_tricks = {}	 --牌墩
	seat.curr_score = 0      --当前得分
	seat.total_score = 0     --总得分
	seat.win_num = 0         --记录胜利次数
	seat.fail_num = 0        --记录玩家失败次数
	seat.draw_num = 0        --记录玩家平局次数 
 	seat.is_leave = false    --是否离开
 	seat.is_banker = false   --是否庄家
	seat.hupai_card = 0        --玩家胡牌的牌 0表示无
	seat.fan_types = {}   	   --翻型数组，如果无就是空数组
	seat.fan_value = 0   	   --总翻值 
end

function RoomSeatLogic.dealtuoguan(gameobj,seat)
end

function RoomSeatLogic.canceltuoguan(gameobj,seat)

end

function RoomSeatLogic.onegamestart_initseat(seat)
	seat.state = ESeatState.SEAT_STATE_PLAYING
	if seat.cards == nil or not tabletool.is_emptytable(seat.cards) then
		seat.cards = {}          --记录玩家手牌
	end

	if seat.cards_tricks == nil or not tabletool.is_emptytable(seat.cards_tricks) then
		seat.cards_tricks = {}
	end

	if seat.fan_types == nil or not tabletool.is_emptytable(seat.fan_types) then
		seat.fan_types = {}
	end

	seat.curr_score = 0      --当前得分
	seat.win = 0
	seat.is_banker = false   --是否庄家
	seat.hupai_card = 0        --玩家胡牌的牌 0表示无
	seat.fan_value = 0   	   --总翻值  
end

function RoomSeatLogic.onegameend_initseat(seat)
	seat.state = ESeatState.SEAT_STATE_WAIT_READY
	if seat.cards == nil or not tabletool.is_emptytable(seat.cards) then
		seat.cards = {}          --记录玩家手牌
	end
	
	if seat.cards_tricks == nil or not tabletool.is_emptytable(seat.cards_tricks) then
		seat.cards_tricks = {}
	end

	if seat.fan_types == nil or not tabletool.is_emptytable(seat.fan_types) then
		seat.fan_types = {}
	end

	seat.curr_score = 0      --当前得分
	seat.win = 0
	seat.is_banker = false   --是否庄家 
	seat.hupai_card = 0        --玩家胡牌的牌 0表示无
	seat.fan_value = 0   	   --总翻值
end

function RoomSeatLogic.deal_player_online(seat,svr_id,id,table_address)
	if not seat then return end
	local leavetablemsg = {
			roomsvr_id = svr_id,
			roomsvr_table_id = id,
			roomsvr_table_address = table_address,
			is_sendto_client = false,
			rid = seat.rid,
	}
	msgproxy.sendrpc_noticemsgto_gatesvrd(seat.gatesvr_id,seat.agent_address, "leavetable", leavetablemsg)
end

return RoomSeatLogic